Bug 41214

Bug Description:

This is a deadlock.
The following is an example of deadlock threads:

"RootLoggerThread": waiting to lock monitor 0x000000000215f648 (object 0x00000007d5eb6de0, 
a org.apache.log4j.ConsoleAppender), which is held by "AnObjectThread"
"AnObjectThread": waiting to lock monitor 0x000000000215ce40 (object 0x00000007d5e47040,
a org.apache.log4j.spi.RootLogger), which is held by "RootLoggerThread"

Java stack information for the threads listed above:
===================================================
"RootLoggerThread":
at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:210)
- waiting to lock <0x00000007d5eb6de0> (a org.apache.log4j.ConsoleAppender) at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:65) at org.apache.log4j.Category.callAppenders(Category.java:203) - locked <0x00000007d5e47040> (a org.apache.log4j.spi.RootLogger) at org.apache.log4j.Category.forcedLog(Category.java:388) at org.apache.log4j.Category.info(Category.java:663) at com.main.RootLoggerThread.run(RootLoggerThread.java:18) "AnObjectThread": at org.apache.log4j.Category.callAppenders(Category.java:202) - waiting to lock <0x00000007d5e47040> (a org.apache.log4j.spi.RootLogger) at org.apache.log4j.Category.forcedLog(Category.java:388) at org.apache.log4j.Category.info(Category.java:663) at com.a.AnObject.toString(AnObject.java:24) at org.apache.log4j.or.DefaultRenderer.doRender(DefaultRenderer.java:35) at org.apache.log4j.or.RendererMap.findAndRender(RendererMap.java:79) at org.apache.log4j.spi.LoggingEvent.getRenderedMessage(LoggingEvent.java:297) at org.apache.log4j.helpers.PatternParser$BasicPatternConverter.convert(PatternParser.java:403) at org.apache.log4j.helpers.PatternConverter.format(PatternConverter.java:64) at org.apache.log4j.PatternLayout.format(PatternLayout.java:503) at org.apache.log4j.WriterAppender.subAppend(WriterAppender.java:301) at org.apache.log4j.WriterAppender.append(WriterAppender.java:159) at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:230) - locked <0x00000007d5eb6de0> (a org.apache.log4j.ConsoleAppender) at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:65) at org.apache.log4j.Category.callAppenders(Category.java:203) - locked <0x00000007d5f3ccb0> (a org.apache.log4j.Logger) at org.apache.log4j.Category.forcedLog(Category.java:388) at org.apache.log4j.Category.info(Category.java:663) at com.c.AnObjectThread.run(AnObjectThread.java:20)
More details about this bug are at LOG4J-41214 JIRA page.

How To Reproduce:

This bug is reproduced under log4j 1.2.13 and JDK 1.6.0_33.
Execute the following scripts to run the test to reproduce the bug (assume the location of the log4j test project is log4j_test_home).

Linux:
${log4j_test_home}/scripts/41214.sh [--monitoroff]
Windows:
%log4j_test_home%\scripts\41214.bat [--monitoroff]

Example: Use monitor to report and terminate the program when deadlock happens:
${log4j_test_home}/scripts/41214.sh


Turn off monitor:
${log4j_test_home}/scripts/41214.sh --monitoroff

Option Function
--monitoroff, -mo Turn off to stop reporting bug messages and ending program when test
runs into the expected concurrency bug which is a deadlock.
User has to terminate the program manually when this option is set.